package com.wimcorp.magic.data;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;



@Entity
@Table(name = "carddata", schema = "carddata")
public class CardData  implements Serializable {

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE)
	private Long id;

	public CardData() {
	}
	
	/*public CardData(long multiverseid,String name) {
		this.multiverseid = multiverseid;
		this.name = name;
	}*/

	public CardData(Set<AbilityData> abilities, Set<BehaviourData> behaviours, Set<TypeData> typesList,
			Set<ColorData> colorsList, long multiverseid, String name, Set<SubTypeData> subtypesList, String power,
			String toughness, String manaCost, String text, int count, int number) {
		this.abilities = abilities;
		this.behaviours = behaviours;
		this.types = typesList;
		this.colors = colorsList;
		this.multiverseid = multiverseid;
		this.name = name;
		this.subtypes = subtypesList;
		this.power = power;
		this.toughness = toughness;
		this.manacost = manaCost;
		this.text = text;
		this.count = count;
		this.number = number;

	}

	public CardData(long multiverseid, String name, String power, String toughness, String manacost, String text,
			int count, int number) {
		this.abilities = new HashSet<AbilityData>();
		this.behaviours = new HashSet<BehaviourData>();
		this.types = new HashSet<TypeData>();
		this.colors = new HashSet<ColorData>();
		this.multiverseid = multiverseid;
		this.name = name;
		this.subtypes = new HashSet<SubTypeData>();
		this.power = power;
		this.toughness = toughness;
		this.manacost = manacost;
		this.text = text;
		this.count = count;
		this.number = number;
	}

	//@Column(unique = true)
	private long multiverseid;
	private String name;
	private String power;
	private String toughness;
	private String manacost;
	private int count;
	private int number;
	@Column(columnDefinition = "text")
	private String text;

	private int loyalty;

	private boolean verified = false;

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "carddata_typedata", schema = "carddata", joinColumns = @JoinColumn(name = "carddata_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "typedata_id", referencedColumnName = "id"))
	private Set<TypeData> types;
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "carddata_colordata", schema = "carddata", joinColumns = @JoinColumn(name = "carddata_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "colordata_id", referencedColumnName = "id"))
	private Set<ColorData> colors;
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "carddata_subtypedata", schema = "carddata", joinColumns = @JoinColumn(name = "carddata_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "subtypedata_id", referencedColumnName = "id"))
	private Set<SubTypeData> subtypes;
	//@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@OneToMany(fetch= FetchType.EAGER,cascade = CascadeType.ALL,orphanRemoval=true)
	@JoinTable(name = "carddata_abilitydata", schema = "carddata", joinColumns = @JoinColumn(name = "carddata_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "abilitydata_id", referencedColumnName = "id"))
	private Set<AbilityData> abilities;
	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "carddata_behaviourdata", schema = "carddata", joinColumns = @JoinColumn(name = "carddata_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "behaviourdata_id", referencedColumnName = "id"))
	private Set<BehaviourData> behaviours;

	@OneToMany(fetch= FetchType.EAGER,cascade = CascadeType.ALL,orphanRemoval=true)
	//@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "carddata_costdata", schema = "carddata", joinColumns = @JoinColumn(name = "carddata_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "cost_id", referencedColumnName = "id"))
	private Set<CostData> costs;

	public long getMultiverseid() {
		return multiverseid;
	}

	public void setMultiverseid(long multiverseid) {
		this.multiverseid = multiverseid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPower() {
		return power;
	}

	public void setPower(String power) {
		this.power = power;
	}

	public String getToughness() {
		return toughness;
	}

	public void setToughness(String toughness) {
		this.toughness = toughness;
	}

	public String getManacost() {
		return manacost;
	}

	public void setManacost(String manacost) {
		this.manacost = manacost;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public Set<TypeData> getTypes() {
		return types;
	}

	public void setTypes(Set<TypeData> types) {
		this.types = types;
	}

	public Set<ColorData> getColors() {
		return colors;
	}

	public void setColors(Set<ColorData> colors) {
		this.colors = colors;
	}

	public Set<SubTypeData> getSubtypes() {
		return subtypes;
	}

	public void setSubtypes(Set<SubTypeData> subtypes) {
		this.subtypes = subtypes;
	}

	public int getLoyalty() {
		return loyalty;
	}

	public void setLoyalty(int loyalty) {
		this.loyalty = loyalty;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public Set<AbilityData> getAbilities() {
		return abilities;
	}

	public void setAbilities(Set<AbilityData> abilities) {
		this.abilities = abilities;
	}

	public Set<BehaviourData> getBehaviours() {
		return behaviours;
	}

	public void setBehaviours(Set<BehaviourData> behaviours) {
		this.behaviours = behaviours;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public int getNumber() {
		return number;
	}

	public void setNumber(int number) {
		this.number = number;
	}

	public boolean isVerified() {
		return verified;
	}

	public void setVerified(boolean verified) {
		this.verified = verified;
	}

	public Set<CostData> getCosts() {
		return costs;
	}

	public void setCosts(Set<CostData> costs) {
		this.costs = costs;
	}

}
